import $http from '../../../servers/http';
import { Result } from '../../schema/Result';
import { GetTaskInfoParam, TaskDialogueInfo, TaskInfo } from 'seats/schema/Task';

/**查询任务列表 */
export const getTaskList = (data: GetTaskInfoParam): Promise<Result<TaskInfo[]>> => {
  console.log('查询列表条件：', data);
  return $http.get({
    url: '/seats/seatstask/tasks',
    data,
  });
};
/**示闲接口 */
export const modifySeatFree = (
  taskId: number,
  data?: {
    templateId?: number;
    seatsSession?: number;
  }
): Promise<Result<null>> => {
  return $http.post({
    url: `/seats/seatstask/tasks/${taskId}/idle`,
    data,
  });
};

/**示忙接口 */
export const modifySeatBusy = (taskId: number): Promise<Result<null>> => {
  return $http.post({
    url: `/seats/seatstask/tasks/${taskId}/busy`,
  });
};

/**心跳接口 */
export const postHeart = (): Promise<Result<null>> => {
  return $http.post(
    {
      url: '/seats/heart?timestamp=' + new Date().getTime(),
    }
    // {
    //   onDownloadProgress: (progress: any) => {
    //     // 下载接口
    //     console.log(progress, '屏蔽报错');
    //     // console.log(Math.round((progress.loaded / progress.total) * 100) + "%");
    //   },
    // }
  );
};
/**修改弹屏数接口 */
export const modifySession = (
  taskId: number,
  data: {
    seatsSession: number;
  }
): Promise<Result<null>> => {
  return $http.post({
    url: `/seats/seatstask/tasks/${taskId}/setseatssession`,
    data,
  });
};
/**小休切换接口 */
export const modifySeatRest = (data: { restSwitch: 'on' | 'off' }): Promise<Result<null>> => {
  return $http.post({
    url: '/seats/seatstask/tasks/rest',
    data,
  });
};
/** 获得某次会话的历史信息 */
export const getDialogue = (
  data: {
    callRecordId: string;
    time: string;
  },
  type?: string
): Promise<Result<TaskDialogueInfo[]>> => {
  return $http.get({
    url: type
      ? '/robotmanage/flowdebugrecords/callrecords/dialogue'
      : '/icms/taskmanage/tasks/callrecords/dialogue',
    data,
  });
};

/**
 * 坐席端-人工介入-拦截通话
 */
export const interceptCall = (
  callId: string,
  data?: { intercepter: string }
): Promise<Result<null>> => {
  return $http.post({
    url: `/icms/taskmanage/tasks/callrecords/intercept/${callId}`,
  });
};

/**
 * 坐席端-人工监听-旁听通话-开启
 */
export const openListenCall = (callId: string): Promise<Result<null>> => {
  return $http.post({
    url: `/seats/seatstask/tasks/eavesdrop/${callId}`,
  });
};

/**
 * 坐席端-人工监听-旁听通话-关闭
 */
export const closeListenCall = (callId: string): Promise<Result<null>> => {
  return $http.delete({
    url: `/seats/seatstask/tasks/eavesdrop/${callId}`,
  });
};
